<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath %>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>农资与农产品全程供应链物流平台-新增用户</title>
<meta name="kewywords" content="农资与农产品全程供应链物流平台"/>
<meta name="description" content="农资与农产品全程供应链物流平台"/>
<link href="css/style.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
	<script type="text/javascript">
		function saveCheck(val){
			if(val==1){
					if ("" == $("#username").val() || $.trim($("#username").val()) == "") {
						$("#usernameTip").html("<font color=\"red\">用户名不能为空</font>");
						return false;
					}else {
						var s= $("#username").val();
						var w = 0;  
						for (var i=0; i<s.length; i++) {   
						   var c = s.charCodeAt(i);   
						   //单字节加1   
						   if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
						    w++;   
						   }   
						   else {   
						    w+=2;   
						   }   
						}   
						if (w>16||w<6) {   
							$("#usernameTip").html("<font color=\"red\">用户名长度在6到16个字节之间</font>");
						}else if(/[\u4E00-\u9FA5]/g.test(s)){
							$("#usernameTip").html("<font color=\"red\">用户名必须是字母和数字组成</font>");
						}else{
							$("#usernameTip").html("<font color=\"red\"></font>");
						 
			                 }
						}
					}
			
			if(val==2){
				if ("" == $("#fullName").val() || $.trim($("#fullName").val()) == "") {
					document.getElementById("nicknameLabe1").innerHTML = "<font color=\"red\">姓名不能为空</font>";
					nickname.focus;
					return false;
				} else {
					document.getElementById("nicknameLabe1").innerHTML = "<font color=\"red\"></font>";
					nickname.focus;
					return false;
				}
				
			}
			if(val==3){
				if ("" == $("#password").val() || $.trim($("#password").val()) == "") {
					$("#passwordTip").html("<font color=\"red\">密码不能为空</font>");
					return false;
				}else {
					var s= $("#password").val();
					var w = 0;   
					for (var i=0; i<s.length; i++) {   
					   var c = s.charCodeAt(i);   
					   //单字节加1   
					   if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
					    w++;   
					   }   
					   else {   
					    w+=2;   
					    
					   }   
					}   
					if (6<=w&&w<=16) {   
						$("#passwordTip").html("<font color=\"red\"></font>");
					}else{
						$("#passwordTip").html("<font color=\"red\">密码长度在6到16个字节之间</font>");
					}   

				}
			}
			if(val==4){
				if ("" == $("#repassword").val() || $.trim($("#repassword").val()) == "") {
					$("#rpasswordTip").html("<font color=\"red\">密码不能为空</font>");
					return false;
				}else{
					var s= $("#password").val();
					var a= $("#repassword").val();
					if(a==s){
						$("#rpasswordTip").html("<font color=\"red\"></font>");
					}
					else{$("#rpasswordTip").html("<font color=\"red\">两次输入的密码不一致</font>");}
					return false;
				}
			}
			if(val==5){
				if ("" == $("#job").val() || $.trim($("#job").val()) == "") {
					$("#jobTip").html("<font color=\"red\">职位不能为空</font>");
					return false;
				} else {
					$("#jobTip").html("<font color=\"red\"></font>");
					return false;
				}
			}
			if(val==6){
				if ("" == $("#phone").val() || $.trim($("#phone").val()) == "") {
					$("#phoneTip").html("<font color=\"red\">联系电话不能为空</font>");
					return false;
				} else {
					var s= $("#phone").val();
					var w = 0;   
					for (var i=0; i<s.length; i++) {   
					   var c = s.charCodeAt(i);   
					   //单字节加1   
					   if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
					    w++;   
					   }   
					   else {   
					    w+=2;   
					    
					   }   
					}   
					if (w==11) {   
						$("#phoneTip").html("<font color=\"red\"></font>");
					}else{
						$("#phoneTip").html("<font color=\"red\">联系电话必须是11位的数字</font>");
					}   
				}
			}
			if(val==7){
				if ("" == $("#email").val() || $.trim($("#email").val()) == "") {
					$("#emailTip").html("<font color=\"red\">Email不能为空</font>");
					return false;
				} else {
					 var temp = document.getElementById("email");
   	              var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
   	           if(!myreg.test(temp.value)){
  	             //对电子邮件的验证
  	                  $("#emailTip").html("<font color=\"red\">邮箱的格式不正确</font>");
  	                   myreg.focus();
  	                 return false;
               }else {
   	              $("#emailTip").html("<font color=\"red\"></font>");
					return false;
               }
				}
			}
			
			if(val==8){
				var socialNo = $("#cardNo").val();
				if(socialNo == ""){
					$("#cardNoTip").html("<font color=\"red\">身份证号码不能为空</font>");
				}
				else if (socialNo != "") {
					if (socialNo.length != 15 && socialNo.length != 18) {
						$("#cardNoTip").html("<font color=\"red\">身份证号码输入长度不正确</font>");
						return (false);
					}
					var area = { 11 : "北京", 12 : "天津", 13 : "河北", 14 : "山西", 15 : "内蒙古", 21 : "辽宁", 22 : "吉林", 23 : "黑龙江", 31 : "上海", 32 : "江苏", 33 : "浙江", 34 : "安徽", 35 : "福建", 36 : "江西", 37 : "山东",
						41 : "河南", 42 : "湖北", 43 : "湖南", 44 : "广东", 45 : "广西", 46 : "海南", 50 : "重庆", 51 : "四川", 52 : "贵州", 53 : "云南", 54 : "西藏", 61 : "陕西", 62 : "甘肃", 63 : "青海", 64 : "宁夏", 65 : "新疆",
						71 : "台湾", 81 : "香港", 82 : "澳门", 91 : "国外" };

					if (area[parseInt(socialNo.substr(0, 2))] == null) {
						$("#cardNoTip").html("<font color=\"red\">身份证号码不正确(地区非法)!</font>");
						return (false);
					}
					if (socialNo.length == 15) {
						pattern = /^\d{15}$/;
						if (pattern.exec(socialNo) == null) {
							$("#cardNoTip").html("<font color=\"red\">15位身份证号码必须全为数字！ </font>");
							return (false);
						}
						var birth = parseInt("19" + socialNo.substr(6, 2));
						var month = socialNo.substr(8, 2);
						var day = parseInt(socialNo.substr(10, 2));
						switch (month) {
						case '01':
						case '03':
						case '05':
						case '07':
						case '08':
						case '10':
						case '12':
							if (day > 31) {
								$("#cardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
								return false;
							}
							break;
						case '04':
						case '06':
						case '09':
						case '11':
							if (day > 30) {
								$("#cardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
								return false;
							}
							break;
						case '02':
							if ((birth % 4 == 0 && birth % 100 != 0) || birth % 400 == 0) {
								if (day > 29) {
									$("#cardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
									return false;
								}
							} else {
								if (day > 28) {
									$("#cardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
									return false;
								}
							}
							break;
						default:
							$("#cardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
							return false;
						}
						if (result<15 || result>100) {
							$("#cardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
							return false;
						}
					} else if (socialNo.length == 18) {
						var Wi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
						var lSum = 0;
						var nNum = 0;

						for (i = 0; i < 17; ++i) {

							if (socialNo.charAt(i) < '0' || socialNo.charAt(i) > '9') {
								$("#cardNoTip").html("<font color=\"red\">输入身份证号码格式不正确! </font>");
								return (false);
							} else {
								nNum = socialNo.charAt(i) - '0';
							}
							lSum += nNum * Wi[i];
						}

						if (socialNo.charAt(17) == 'X' || socialNo.charAt(17) == 'x') {
							lSum += 10 * Wi[17];
						} else if (socialNo.charAt(17) < '0' || socialNo.charAt(17) > '9') {
							$("#cardNoTip").html("<font color=\"red\">输入身份证号码格式不正确! </font>");
							return (false);
						} else {
							$("#cardNoTip").html("<font color=\"red\"></font>");
						}
					}
				} 
					
				
			}
			if(val==9){
				if ("" == $("#area").val() || $.trim($("#area").val()) == "") {
					$("#areaTip").html("<font color=\"red\">所属区域不能为空</font>");
					return false;
				} else {
					$("#areaTip").html("<font color=\"red\"></font>");
					return false;
				}
			}
		}
			
		
		function  savecheck(){
			if ("" == $("#area").val() || $.trim($("#area").val()) == ""||$("#cardNo").val()==""||"" == $("#email").val() || $.trim($("#email").val()) == ""
				||"" == $("#phone").val() || $.trim($("#phone").val()) == ""||"" == $("#job").val() || $.trim($("#job").val()) == ""||
				"" == $("#repassword").val() || $.trim($("#repassword").val()) == ""||"" == $("#password").val() || $.trim($("#password").val()) == ""
				||"" == $("#fullName").val() || $.trim($("#fullName").val()) == ""||"" == $("#username").val() || $.trim($("#username").val()) == "") {
			alert("有带“*”号的表格没有填写，请填写完整！");
			return false;
			} else {
			$("#addUser").submit();
			}
		}
		
		
	</script>
</head>
<body>
<%@include file="top.jsp" %>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
	    <td width="187" height="37" bgcolor="#e0e0e0" class="brt bbt">
	    	<div class="topleft fl">系统菜单栏</div></td>
	    <td bgcolor="#e7e7e7" class=" bbt">
	    	<div class="topleft fl">您现在的位置：<a href="#">首页</a>&nbsp;>&nbsp;<span>新增用户</span></div>
	    </td>
	</tr>
	<tr>
	    <td width="187" height="100%" valign="top" bgcolor="#FFFFFF" class="brt">
	    	<div class="left_bk">
				<div class="menu2">
	             <%@include file="system_left.jsp" %>        
	        	</div>
	        </div>
	    </td>
	    <td align="left" valign="top" bgcolor="#FFFFFF">
	    	<div class="content">
		    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td height="38" style="background:url(images/zz_tit.jpg) left top repeat-x;">
						<div class="tt_back fl">新增用户</div>
						<div class="fr">
							<img src="images/tit_right.jpg" alt="" width="103" height="38" />
						</div>
					</td>
		        </tr>
		        <tr>
					<td class="borders btn">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td bgcolor="#fffeee" style="border-bottom:#fee7bd solid 1px;" >
								   	<form id="addUser" action="system/addUser" method="post">	
								    <table border="0" cellspacing="0" cellpadding="0" align="left" style="margin-top:20px;margin-left: 100px;margin-bottom: 20px; " >
				                        <tr style="height: 40px;">
								  			<td align="right" width="200px;"><span style="color: red">*</span>账号：</td>
								  			<td  width="180px;"><input type="text" style="width: 200px;" class="input_are w122" id="username" name="username" value="${admininfo.username}" onblur="saveCheck(1)"/><span id="usernameTip"></span></td>
								  			<td align="right" width="200px;"><span style="color: red">*</span>姓名：</td>
								  			<td  width="180px;"><input type="text" style="width: 200px;" class="input_are w122" id="fullName" name="fullName" value="${admininfo.fullName}" onblur="saveCheck(2)"/><label
													id="nicknameLabe1"></label></td>
								  		</tr>
								  		<tr style="height: 40px;">
								  			<td align="right"><span style="color: red">*</span>密码：</td>
								  			<td width="180px;"><input type="password" style="width: 200px;" id="password" class="input_are w122" name="passwd" onblur="saveCheck(3)"/><span id="passwordTip"></span></td>
								  		    <td align="right" width="200px;"><span style="color: red">*</span>账户类型：</td>
								  			<td  width="180px;">
								  			  <select name="accountType">
								  			      <option value="1">系统管理员</option>
								  			      <option value="2" selected="selected">普通用户</option>
								  			   </select>
								  			</td>
								  		</tr>
								  		<tr style="height: 40px;">
								  			<td align="right"><span style="color: red">*</span>再次输入密码：</td>
								  			<td width="180px;"><input type="password"  style="width: 200px;" id="repassword" class="input_are w122"  onblur="saveCheck(4)"/><span id="rpasswordTip"></span></td>
								  		    <td align="right" width="200px;"> <span style="color: red">*</span>身份证号码：</td>
								  			<td  width="180px">
								  				<input type="text" style="width: 200px;" class="input_are w122" id="cardNo" name="cardNo" value="${admininfo.cardNo}"  onblur="saveCheck(8)"/><span id="cardNoTip"></span></td>
								  		</tr>
								  		<tr style="height: 40px;">
								  			<td align="right"><span style="color: red">*</span>职位：</td>
								  			<td width="180px;">
								  				  <select name="job" id="job">
								  			      <option value="">=请选择=</option>
								  			      <option value="管理员" >管理员</option>
								  			      <option value="仓管员" >仓管员</option>
								  			      <option value="司机" >司机</option>
								  			      <option value="配送员" >配送员</option>
								  			       <option value="站点管理员" >站点管理员</option>
								  			   </select></td>
								  		    <td align="right" width="200px;"><span style="color: red">*</span>所属区域：</td>
								  			<td  width="180px;">
								  				<input type="text" style="width: 200px;" class="input_are w122" id="area" name="area" value="${admininfo.area}" onblur="saveCheck(9)"/><span id="areaTip"></span></td>
								  		</tr>
								  		<tr style="height: 40px;">
								  			<td align="right"><span style="color: red">*</span>联系电话：</td>
								  			<td width="180px;">
								  				<input type="text" style="width: 200px;" id="phone" class="input_are w122" name="phone" value="${admininfo.phone}" onblur="saveCheck(6)"/><span id="phoneTip"></span></td>
								  		    <td align="right">住址：</td>
								  			<td width="180px;">
								  				<input type="text" style="width: 200px;" id="addre" class="input_are w122" name="addre" value="${admininfo.addre}" onblur="saveCheck(10)"/><span id="addreTip"></span></td>
								  		</tr>
								  		<tr style="height: 40px;">
								  			<td align="right"><span style="color: red">*</span>E-mail：</td>
								  			<td width="180px;">
								  				<input type="text" style="width: 200px;" id="email" class="input_are w122" name="email" value="${admininfo.email}" onblur="saveCheck(7)"/><span id="emailTip"></span></td>
								  		    <td align="right">备注：</td>
								  			<td width="180px;">
								  				<input type="text" style="width: 200px;" id="remark" class="input_are w122" name="remark" value="${admininfo.remark}" /></td>
								  		</tr>
								  		<tr style="height: 60px;">
								  			<td colspan="4" align="center">
								  			<input type="button" style="cursor: pointer;" class="buttons2" value="保存" onclick="savecheck()"/>
								  			&nbsp;&nbsp;&nbsp;&nbsp;
								  			<input type="reset" style="cursor: pointer;" class="buttons2" value="重 置" /></td>
								  		</tr>
									</table>
									</form>
								</td>
			  				</tr>
						</table>
					</td>
				</tr>
			</table>
			</div>
		</td>
	</tr>
</table>
<div class="bottom">版权所有：安徽朗坤物联网</div>
</body>
</html>